/**
 * @file   PA_B.cpp
 * @author ZL <zuoling@Black>
 * @date   Fri Oct  7 00:52:25 2022
 * 
 * @brief  1.8.2 PA_B
 * 
 * 
 */
#include "EquationSolver.h"
/** 
 * 
 * 
 * 
 * @return define the first function in problemB 
 */
class F1 : public Function
{
public:
    double operator ()(double _x)
	{
	    double x = _x;
	    double y;
	    y = pow(x,-1)-tan(x);
	    return y;
	};
};

/** 
 * 
 * 
 * 
 * @return define the second function in problemB 
 */
class F2 : public Function
{
public:
    double operator ()(double _x)
	{
	    double x = _x;
	    double y;
	    y = pow(x,-1)-pow(2,x);
	    return y;
	};
};

/** 
 * 
 * 
 * 
 * @return define the third function in problemB 
 */
class F3 : public Function
{
public:
    double operator ()(double _x)
	{
	    double x = _x;
	    double y;
	    y = pow(2,-x)+exp(x)+2*cos(x)-6;
	    return y;
	};
};

/** 
 * 
 * 
 * 
 * @return define the fourth function in problemB 
 */
class F4 : public Function
{
public:
    double operator ()(double _x)
	{
	    double x = _x;
	    double y;
	    y = (pow(x,3)+4*pow(x,2)+3*x+5)/(2*pow(x,3)-9*pow(x,2)+18*x-2);
	    return y;
	};
};

int main(int argc, char* argv[])
{
    F1 f1;
    F2 f2;
    F3 f3;
    F4 f4;/// create four corresponding functions.
    Bisection b1(0, pi/2, eps, 20, f1);
    Bisection b2(0, 1, eps, 20, f2);
    Bisection b3(1, 3, eps, 20, f3);
    Bisection b4(0, 4, eps, 20, f4);/// generate corresponding solver according to known conditions.
    double y1 = b1.solve();
    double y2 = b2.solve();
    double y3 = b3.solve();
    double y4 = b4.solve();/// Assign the calculated root to the corresponding y.

    std::cout << "function1'root is r1 = " << y1 <<", f(r) = "<< (f1)(y1)<<std::endl;
    std::cout << "function2'root is r2 = " << y2 <<", f(r) = "<< (f2)(y2)<<std::endl;
    std::cout << "function3'root is r3 = " << y3 <<", f(r) = "<< (f3)(y3)<<std::endl;
    std::cout << "function4'root is r4 = " << y4 <<", f(r) = "<< (f4)(y4)<<std::endl; /// Output root and corresponding function value.
    return 0;
};
